var a = require("../../requests/request.js");

getApp();

Page({
    data: {
        currentTab: 0,
        winHeight: 0,
        initails: [],
        pageindex: 1,
        year: "2018",
        month: "3",
        energyList: {},
        masterList: [],
        currentCityID: 0,
        saleList: {},
        isloadsale: !1,
        issaleend: !1,
        currentCityName: "qg",
        cityList: [ {
            py: "qg",
            name: "全国"
        }, {
            py: "bj",
            name: "北京"
        }, {
            py: "sh",
            name: "上海"
        }, {
            py: "sz",
            name: "深圳"
        }, {
            py: "gz",
            name: "广州"
        }, {
            py: "tj",
            name: "天津"
        }, {
            py: "nj",
            name: "南京"
        }, {
            py: "cq",
            name: "重庆"
        }, {
            py: "wh",
            name: "武汉"
        }, {
            py: "hz",
            name: "杭州"
        }, {
            py: "js",
            name: "江苏"
        }, {
            py: "xa",
            name: "西安"
        }, {
            py: "dl",
            name: "大连"
        }, {
            py: "qh",
            name: "青海"
        }, {
            py: "hk",
            name: "海口"
        } ],
        pagesource: ""
    },
    onLoad: function(a) {
        var e = this, t = "";
        a.pagesource && (t = a.pagesource), wx.getSystemInfo({
            success: function(a) {
                e.setData({
                    winHeight: a.windowHeight,
                    pagesource: t
                });
            }
        }), e.loadEnergyData(), e.getIndexMonth();
    },
    onShareAppMessage: function() {
        return {
            title: "新能源，在线查询汽车报价、车型参数、汽车图片和汽车资讯",
            path: "/pages/energycar/energycar?pagesource=wxshare"
        };
    },
    onShow: function() {},
    onReady: function(a) {},
    onPullDownRefresh: function() {
        this.loadEnergyData(), this.getIndexMonth(), wx.stopPullDownRefresh();
    },
    loadEnergyData: function() {
        var e = this;
        a.getEnergyList(function(a) {
            for (var t = [], n = [], r = [], s = 0; s < a.length - 1; s++) {
                var i = a[s];
                if (i.Picture ? i.Picture = i.Picture.replace("{0}", "3") : i.Picture = "http://res.app.yiche.com/wechatapp/async100x100.png", 
                "16" == i.NewEnergy ? i.NewTypeName = "纯电动" : "128" == i.NewEnergy && (i.NewTypeName = "插电混动"), 
                t.contains(i.MasterInitial) || t.push(i.MasterInitial), !r.contains(i.MasterName)) {
                    r.push(i.MasterName);
                    var u = {};
                    u.initnum = i.MasterInitial, u.mastername = i.MasterName, n.push(u);
                }
            }
            e.setData({
                initails: t.sort(),
                masterList: n,
                energyList: a.sort(function(a, e) {
                    return a.UV - e.UV;
                })
            });
        });
    },
    loadSaleData: function() {
        var e = this;
        e.data.isloadsale || e.data.issaleend || (e.setData({
            isloadsale: !0
        }), a.getIndexData("newenergy", e.data.year, e.data.month, e.data.pageindex, 20, 4, function(a) {
            var t = a.Data;
            t.length < 20 && e.setData({
                issaleend: !0
            }), e.data.saleList.length > 0 && (t = e.data.saleList.concat(a.Data)), e.setData({
                isloadsale: !1,
                saleList: t,
                pageindex: e.data.pageindex + 1
            });
        }));
    },
    getIndexMonth: function() {
        var e = this;
        a.getIndexMonth("newenergy", function(a) {
            e.setData({
                year: a.Year,
                month: a.DateNum
            }), e.loadSaleData();
        });
    },
    clickCar: function(a) {
        var e = a.currentTarget.dataset.id, t = a.currentTarget.dataset.name;
        wx.navigateTo({
            url: "../summary/summary?id=" + e + "&name=" + t
        });
    },
    toDetailPage: function(a) {
        var e = a.currentTarget.dataset.id, t = a.currentTarget.dataset.name;
        wx.navigateTo({
            url: "../summary/summary?id=" + e + "&name=" + t
        });
    },
    scrollNum: function(a) {
        var e = a.currentTarget.dataset.num;
        this.setData({
            toNum: e
        });
    },
    swichNav: function(a) {
        var e = this;
        if (e.data.currentTab === a.currentTarget.dataset.current) return !1;
        e.setData({
            currentTab: a.currentTarget.dataset.current
        });
    },
    swiperchange: function(a) {
        var e = this, t = "新能源";
        1 == a.detail.current && (t = e.data.month + "月新能源销量"), wx.setNavigationBarTitle({
            title: t
        }), e.setData({
            currentTab: a.detail.current
        });
    },
    scrollCity: function(a) {
        var e = a.currentTarget.dataset.cityid, t = a.currentTarget.dataset.flag;
        this.setData({
            currentCityID: e,
            currentCityName: t
        });
    }
});